{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "30bc1765",
   "metadata": {},
   "source": [
    "while循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "71157167",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "count = 0\n",
    "while count <= 9:\n",
    "    print(count)\n",
    "    count += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "bc2516e2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1 2 3 4 5 6 7 8 9 \n"
     ]
    }
   ],
   "source": [
    "result = \"\" # 空字符串\n",
    "count = 0\n",
    "while count <= 9:\n",
    "    result += str(count)+\" \"\n",
    "    count += 1 # count = count + 1\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "25ea96d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1 2 3 4 5 6 7 8 9 \n",
      "done\n"
     ]
    }
   ],
   "source": [
    "count = 0\n",
    "while count <= 9:\n",
    "    print(count, end=\" \")\n",
    "    count += 1\n",
    "print()\n",
    "print(\"done\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d00188b",
   "metadata": {},
   "source": [
    "for循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "58e9c36e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tom\n",
      "Peter\n",
      "Jerry\n",
      "Jack\n"
     ]
    }
   ],
   "source": [
    "names = ['Tom','Peter', 'Jerry', 'Jack']\n",
    "for name in names:\n",
    "    print(name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "d9c6a2f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "s\n",
      "i\n",
      "x\n",
      " \n",
      " \n",
      "尚\n",
      " \n",
      "学\n",
      " \n",
      "堂\n",
      " \n",
      "-\n"
     ]
    }
   ],
   "source": [
    "for x in \"six  尚 学 堂 -\":\n",
    "    print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1e562f86",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 4)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "89d2cf41",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "de1160fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tom\n",
      "Peter\n",
      "Jerry\n",
      "Jack\n"
     ]
    }
   ],
   "source": [
    "for i in range(len(names)):\n",
    "    print(names[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "be29a838",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "djaksd*2fs2.340000\n"
     ]
    }
   ],
   "source": [
    "a = 2\n",
    "b = 2.34\n",
    "c = \"djaksd\"\n",
    "print(\"%s*%dfs%f\"%(c,a,b))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "134dee48",
   "metadata": {},
   "source": [
    "打印九九乘法表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "810519a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1\t2*1=2\t3*1=3\t4*1=4\t5*1=5\t6*1=6\t7*1=7\t8*1=8\t9*1=9\t\n",
      "1*2=2\t2*2=4\t3*2=6\t4*2=8\t5*2=10\t6*2=12\t7*2=14\t8*2=16\t9*2=18\t\n",
      "1*3=3\t2*3=6\t3*3=9\t4*3=12\t5*3=15\t6*3=18\t7*3=21\t8*3=24\t9*3=27\t\n",
      "1*4=4\t2*4=8\t3*4=12\t4*4=16\t5*4=20\t6*4=24\t7*4=28\t8*4=32\t9*4=36\t\n",
      "1*5=5\t2*5=10\t3*5=15\t4*5=20\t5*5=25\t6*5=30\t7*5=35\t8*5=40\t9*5=45\t\n",
      "1*6=6\t2*6=12\t3*6=18\t4*6=24\t5*6=30\t6*6=36\t7*6=42\t8*6=48\t9*6=54\t\n",
      "1*7=7\t2*7=14\t3*7=21\t4*7=28\t5*7=35\t6*7=42\t7*7=49\t8*7=56\t9*7=63\t\n",
      "1*8=8\t2*8=16\t3*8=24\t4*8=32\t5*8=40\t6*8=48\t7*8=56\t8*8=64\t9*8=72\t\n",
      "1*9=9\t2*9=18\t3*9=27\t4*9=36\t5*9=45\t6*9=54\t7*9=63\t8*9=72\t9*9=81\t\n"
     ]
    }
   ],
   "source": [
    "j=1\n",
    "while j <= 9:\n",
    "    i = 1\n",
    "    while i <= 9:\n",
    "        print(\"%d*%d=%d\"%(i,j,i*j),end=\"\\t\")\n",
    "        i += 1\n",
    "    j += 1\n",
    "    print()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "39fc4d63",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1\t\n",
      "2*1=2\t2*2=4\t\n",
      "3*1=3\t3*2=6\t3*3=9\t\n",
      "4*1=4\t4*2=8\t4*3=12\t4*4=16\t\n",
      "5*1=5\t5*2=10\t5*3=15\t5*4=20\t5*5=25\t\n",
      "6*1=6\t6*2=12\t6*3=18\t6*4=24\t6*5=30\t6*6=36\t\n",
      "7*1=7\t7*2=14\t7*3=21\t7*4=28\t7*5=35\t7*6=42\t7*7=49\t\n",
      "8*1=8\t8*2=16\t8*3=24\t8*4=32\t8*5=40\t8*6=48\t8*7=56\t8*8=64\t\n",
      "9*1=9\t9*2=18\t9*3=27\t9*4=36\t9*5=45\t9*6=54\t9*7=63\t9*8=72\t9*9=81\t\n"
     ]
    }
   ],
   "source": [
    "j=1\n",
    "while j <= 9:\n",
    "    i = 1\n",
    "    while i <= j:\n",
    "        print(\"%d*%d=%d\"%(j,i,i*j),end='\\t')\n",
    "        i += 1\n",
    "    print()\n",
    "    j += 1\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "17df2660",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 2)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,10,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "6703d9c5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 3, 5, 7, 9]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(1,10,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "97f8eae7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1\t\n",
      "2*1=2\t2*2=4\t\n",
      "3*1=3\t3*2=6\t3*3=9\t\n",
      "4*1=4\t4*2=8\t4*3=12\t4*4=16\t\n",
      "5*1=5\t5*2=10\t5*3=15\t5*4=20\t5*5=25\t\n",
      "6*1=6\t6*2=12\t6*3=18\t6*4=24\t6*5=30\t6*6=36\t\n",
      "7*1=7\t7*2=14\t7*3=21\t7*4=28\t7*5=35\t7*6=42\t7*7=49\t\n",
      "8*1=8\t8*2=16\t8*3=24\t8*4=32\t8*5=40\t8*6=48\t8*7=56\t8*8=64\t\n",
      "9*1=9\t9*2=18\t9*3=27\t9*4=36\t9*5=45\t9*6=54\t9*7=63\t9*8=72\t9*9=81\t\n"
     ]
    }
   ],
   "source": [
    "for j in range(1, 10):\n",
    "    for i in range(1, j+1):\n",
    "        print(\"%d*%d=%d\"%(j,i,i*j),end='\\t')\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "03fe0849",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1\t\n",
      "2*1=2\t2*2=4\t\n",
      "3*1=3\t3*2=6\t3*3=9\t\n",
      "4*1=4\t4*2=8\t4*3=12\t4*4=16\t\n",
      "5*1=5\t5*2=10\t5*3=15\t5*4=20\t5*5=25\t\n",
      "6*1=6\t6*2=12\t6*3=18\t6*4=24\t6*5=30\t6*6=36\t\n",
      "7*1=7\t7*2=14\t7*3=21\t7*4=28\t7*5=35\t7*6=42\t7*7=49\t\n",
      "8*1=8\t8*2=16\t8*3=24\t8*4=32\t8*5=40\t8*6=48\t8*7=56\t8*8=64\t\n",
      "9*1=9\t9*2=18\t9*3=27\t9*4=36\t9*5=45\t9*6=54\t9*7=63\t9*8=72\t9*9=81\t\n"
     ]
    }
   ],
   "source": [
    "for j in range(1, 10):\n",
    "    for i in range(1, j+1):\n",
    "        print(f\"{j}*{i}={i*j}\",end='\\t')\n",
    "    print()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "my_test",
   "language": "python",
   "name": "my_test"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
